/**
 * Created by wanghuan on 2017/4/9.
 */

/*==========================timesheet 相关接口==============================*/

import Ajax from '../../apiAjax';

export  default {
  state:{
    timesheets:{},
    timesheet:{},
    timezoneList:[],
  },
  mutations:{
    setCommonStateData(state,{key,data}){
      state[key] = data;
    }
  },
  actions:{

    getTimesheets({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/timesheet/getTimesheetList',
          data:JSON.stringify(paramData),
          contentType: "application/json;charset=UTF-8",
          success:function (data) {
            commit('setCommonStateData',{key:'timesheets',data:data.data});
            resolve(data);
          }
        })
      })
    },
    /**
     * 查询单个timesheet
     * @param commit
     * @param paramData= {id:}
     * @returns {Promise}
     */
    getTimesheet({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/timesheet/getTimesheet',
          data:paramData,
          type:'get',
          success:function (data) {
            commit('setCommonStateData',{key:'timesheet',data:data.data});
            resolve(data);
          }
        })
      })
    },
    saveTimesheet({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/timesheet/saveTimesheet',
          data:JSON.stringify(paramData),
          contentType: "application/json;charset=UTF-8",
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
    deleteTimesheet({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/timesheet/delTimesheet',
          data:paramData,
          success:function (data) {
            resolve(data);
          }
        })
      })
    },
    getAllTimezone({commit},paramData){
      return new Promise((resolve, reject) => {
        Ajax({
          url:'/time/timezone/getAllTimezone',
          data:paramData,
          type:'get',
          success:function (data) {
            commit('setCommonStateData',{key:'timezoneList',data:data.data});
            resolve(data);
          }
        })
      })
    },
  },
  getters: {

    timesheets: (state, getters) => {
      return state.timesheets;
    },
    timesheet: (state, getters) => {
      return state.timesheet;
    },
    timezoneList: (state, getters) => {
      return state.timezoneList;
    },
  }
}
